<?php

use Illuminate\Database\Seeder;
use App\Models\Category;
use Carbon\Carbon;
class CategoriesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $faker = app(Faker\Generator::class);
        $array = ['剧情','喜剧','动作','爱情','惊悚','犯罪', '悬疑', '战争', '科幻', '动画', '恐怖', '家庭', '传记', '冒险', '奇幻', '武侠', '历史', '运动', '歌舞', '音乐', '纪录', '伦理', '西部'];
        
        foreach($array as $k => $name) {
            $now = Carbon::now();
            $created_at = $now->sub(rand(1,15) .' day');
            $categories_array[] = [
                'name' => $name,
                'sort' => $k,
                'created_at' => $created_at,
                'updated_at' => $faker->dateTimeBetween($created_at, 'now'),
            ];
        }

        if (Category::count() <= 0) {
            Category::insert($categories_array);
        }
    }
}
